package com.czl.module_storehouse.mvp.presenter;

import com.czl.module_base.bean.ListBean;
import com.czl.module_base.http.HttpResponse;
import com.czl.module_base.mvp.presenter.BasePresenter;
import com.czl.module_base.observer.AbsHandleSubscriber;
import com.czl.module_storehouse.bean.AddMoveInfoBean;
import com.czl.module_storehouse.bean.AllocateBean;
import com.czl.module_storehouse.bean.AllocateInBean;
import com.czl.module_storehouse.bean.AllocateOutBean;
import com.czl.module_storehouse.mvp.model.AllocateModel;
import com.czl.module_storehouse.mvp.view.AllocateView;

/**
 * @author xubin
 */
public class AllocatePresenter extends BasePresenter<AllocateModel, AllocateView> {

    public static final String TAG_ALLOCATE_MOVE_STORAGE = "allocate_move_storage";
    public static final String TAG_ALLOCATE_EDIT_MOVE_INFO = "allocate_edit_move_info";
    public static final String TAG_NEED_DEALT_MOVE_NEW_SORT_INFO = "need_dealt_move_new_sort_info";
    public static final String TAG_ALLOCATE_ADD_MOVE_INFO = "allocate_add_move_info";

    public void addMoveInfo(AddMoveInfoBean bean) {
        doSubscribe2(mModel.addMoveInfo(bean), new AbsHandleSubscriber<HttpResponse<Object>>() {
            @Override
            public void onSuccess(HttpResponse<Object> httpResponse) {
                httpResponse.setRequestTag(TAG_ALLOCATE_ADD_MOVE_INFO);
                mView.showHttpResponse(httpResponse);
            }
        });
    }

    public void editMoveInfo(AllocateOutBean bean) {
        doSubscribe2(mModel.editMoveInfo(bean), new AbsHandleSubscriber<HttpResponse<Object>>() {
            @Override
            public void onSuccess(HttpResponse<Object> httpResponse) {
                httpResponse.setRequestTag(TAG_ALLOCATE_EDIT_MOVE_INFO);
                mView.showHttpResponse(httpResponse);
            }
        });
    }

    /**
     * 调拨入库
     *
     * @param bean
     */
    public void moveStorage(AllocateInBean bean) {
        doSubscribe2(mModel.moveStorage(bean), new AbsHandleSubscriber<HttpResponse<Object>>() {
            @Override
            public void onSuccess(HttpResponse<Object> httpResponse) {
                httpResponse.setRequestTag(TAG_ALLOCATE_MOVE_STORAGE);
                mView.showHttpResponse(httpResponse);
            }
        });
    }

    public void getNeedDealtMoveNewSortInfo(int moveId) {
        doSubscribe(mModel.getNeedDealtMoveNewSortInfo(moveId), new AbsHandleSubscriber<HttpResponse<AllocateBean>>() {
            @Override
            public void onSuccess(HttpResponse<AllocateBean> httpResponse) {
                httpResponse.setRequestTag(TAG_NEED_DEALT_MOVE_NEW_SORT_INFO);
                mView.showHttpResponse(httpResponse);
            }
        });
    }

    public void getNeedDealtMoveList(boolean refresh) {
        resetPageNo(refresh);
        doSubscribe(mModel.getNeedDealtMoveList(mPageNo), new AbsHandleSubscriber<HttpResponse<ListBean<AllocateBean>>>(mView) {
            @Override
            public void onSuccess(HttpResponse<ListBean<AllocateBean>> httpResponse) {
                mView.showData(httpResponse.getData());
                nextPageNo();
            }
        });
    }

    public void getDealtMoveList(boolean refresh) {
        resetPageNo(refresh);
        doSubscribe(mModel.getDealtMoveList(mPageNo), new AbsHandleSubscriber<HttpResponse<ListBean<AllocateBean>>>(mView) {
            @Override
            public void onSuccess(HttpResponse<ListBean<AllocateBean>> httpResponse) {
                mView.showData(httpResponse.getData());
                nextPageNo();
            }
        });
    }
}
